package com.situ.crm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.crm.entity.Contract;
import com.situ.crm.entity.Student;
import com.situ.crm.service.IStudentService;
import com.situ.crm.vo.ResultDataVO;

@Controller
@RequestMapping("/stu")
public class StudentController {

    @Autowired
    private IStudentService studentService;

    //打开学生管理页面
    @GetMapping(value = "/index")
    public String openPage() {
        return "student";
    }

    //查询学生列表数据
    @GetMapping(value = "/list")
    @ResponseBody
    public ResultDataVO selectStudentList(String name, String status, Integer page, Integer limit) {
        return studentService.selectStudentList(name, status, page, limit);
    }

    @PostMapping(value = "/save")
    @ResponseBody
    public void saveStudent(Student student) {
        studentService.doSave(student);
    }

    @GetMapping(value = "/{id}")
    @ResponseBody
    public Student selectStudentById(@PathVariable("id") Integer id) {
        return studentService.selectStudentById(id);
    }

    @PostMapping(value = "/del")
    @ResponseBody
    public void deleteStudentById(Integer id) {
        studentService.del(id);
    }

    //保存学生合同接口
    @PostMapping(value = "/saveContract")
    @ResponseBody
    public void saveContract(Contract contract) {
        studentService.saveContract(contract);
    }

    @PostMapping(value = "/saveClazz")
    @ResponseBody
    public void saveClazz(Integer clazzId, Integer stuId) {
        studentService.saveClazz(clazzId, stuId);
    }

    //生成邀请码
    @GetMapping(value = "/inviteCode")
    @ResponseBody
    public String generateInviteCode(Integer stuId){
        return studentService.generateInviteCode(stuId);
    }
}
